package javaLanguage.javaMultithread;

import java.util.ArrayList;

public class deadLock {
    private final ArrayList<Integer> temp1 = new ArrayList<>();
    private final ArrayList<Integer> temp2 = new ArrayList<>();

    public class thread1 extends Thread{
        @Override
        public void run() {
            synchronized (temp1){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (temp2){
                    System.out.printf("请求temp2......");
                }
            }
        }
    }

    public class thread2 extends Thread{
        @Override
        public void run() {
            synchronized (temp2){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (temp1){
                    System.out.printf("请求temp1....");
                }
            }
        }
    }

    public static void main(String[] args) {
        deadLock temp = new deadLock();
        thread1 a = temp.new thread1();
        a.start();
        thread2 b = temp.new thread2();
        b.start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.printf("阿斯顿利夫卡是、");
            }
        }).start();
    }
}
